package cc.autoapi.pucong.auto.flow.persistence.utils;


import cc.autoapi.pucong.auto.flow.core.root.entity.UserJwt;
import cc.autoapi.pucong.auto.flow.core.root.utils.ApplicationContextUtil;
import cc.autoapi.pucong.auto.flow.persistence.repository.api.AutoFlowAuthInterceptor;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class UserRequest {

    /**
     * 获取当前登录用户
     *
     * @return
     */
    public static UserJwt getLoginUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        AutoFlowAuthInterceptor autoFlowAuthInterceptor = (AutoFlowAuthInterceptor) ApplicationContextUtil.getBean(AutoFlowAuthInterceptor.class);
        return autoFlowAuthInterceptor.getLoginUser(request);
    }
}
